// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ECUnitOfWork.cs" company="emrecoskun.net">
//   ecblog.codeplex.com - emrecoskun.net
// </copyright>
// <summary>
//   The ec unit of work
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace EcBlog.Data.Sql
{
    using System.ComponentModel.Composition;

    using EcBlog.Data;
    using EcBlog.Data.Sql.Base;

    /// <summary>
    /// The ec unit of work
    /// </summary>
    [Export(typeof(IEcUnitOfWork))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class EcUnitOfWork : UnitOfWork, IEcUnitOfWork
    {
        private readonly EcModelContext context;
        private ICommentRepository commentRepository;
        private ILayoutRepository layoutRepository;
        private IPageRepository pageRepository;
        private ISiteSettingRepository siteSettingRepository;
        private ITagRepository tagRepository;
        private IUserRepository userRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="EcUnitOfWork"/> class.
        /// </summary>
        [ImportingConstructor]
        public EcUnitOfWork()
            : this(new EcModelContext())
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EcUnitOfWork"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public EcUnitOfWork(EcModelContext context) : base(context)
        {
            this.context = context;
        }

        /// <summary>
        /// Gets CommentRepository.
        /// </summary>
        public ICommentRepository CommentRepository
        {
            get { return this.commentRepository ?? (this.commentRepository = new CommentRepository(this.context)); }
        }

        /// <summary>
        /// Gets LayoutRepository.
        /// </summary>
        public ILayoutRepository LayoutRepository
        {
            get { return this.layoutRepository ?? (this.layoutRepository = new LayoutRepository(this.context)); }
        }

        /// <summary>
        /// Gets PageRepository.
        /// </summary>
        public IPageRepository PageRepository
        {
            get { return this.pageRepository ?? (this.pageRepository = new PageRepository(this.context)); }
        }

        /// <summary>
        /// Gets SiteSettingRepository.
        /// </summary>
        public ISiteSettingRepository SiteSettingRepository
        {
            get { return this.siteSettingRepository ?? (this.siteSettingRepository = new SiteSettingRepository(this.context)); }
        }

        /// <summary>
        /// Gets TagRepository.
        /// </summary>
        public ITagRepository TagRepository
        {
            get { return this.tagRepository ?? (this.tagRepository = new TagRepository(this.context)); }
        }

        /// <summary>
        /// Gets UserRepository.
        /// </summary>
        public IUserRepository UserRepository
        {
            get { return this.userRepository ?? (this.userRepository = new UserRepository(this.context)); }
        }
    }
}